ColdFusion Article

WSDLerator: Web Services Execution and Testing Component

Web services are increasingly becoming a regular part of our development lives, both in terms of consuming and developing. For those of you who don't work with web services yet, they are basically sets of methods that can be called on programmatically over the web using a series of XML specifications. The strength of web services is that they allow disparate environments—applications developed in Microsoft .NET, J2EE, ColdFusion, PHP, and just about anything else—to interact with one another over a network.

However, working with web services often requires reading XML files manually directly—specifically, WSDL (Web Services Description Language) files, which are responsible for defining a given web service: what the service is, what remote methods are available, and what type of data should be sent to or received from the web service. WSDLerator provides an interface to simplify this WSDL reading.

WSDLerator comprises two basic parts:

  • <cf_wsdl> custom tag allows developers to retrieve information about a web service by specifying the WSDL location. This information is returned to ColdFusion and simplifies the process of working dynamically with web services in ColdFusion.
  • Dynamic Form Builder uses the <cf_wsdl> tag to interact dynamically with web service data. After the user enters the WSDL location, the form builder allows the user to select from the methods available, enter any information necessary, and finally invoke the service. This is a quick method for testing web services without having to write a lick of code.

Installing WSDLerator

Follow these steps to install WSDLerator:

  1. Extract the contents of the ZIP file to the root (or subdirectory) of your ColdFusion server.
  2. If you wish to use WSDLerator in all of your ColdFusion applications, you need to copy wsdl.cfm into your ColdFusion Custom Tags directory.
  3. Launch WSDLerator in your browser. If you installed it to the WSDLerator directory at the ColdFusion root, this would be http://localhost:8500/WSDLerator/.

Using the Dynamic Form Builder

WSDLerator's Dynamic Form Builder (DFB) walks you through the invocation of a web service using a web-based interface. The DFB is located at http://{WSDLerator_Root}/formBuilder.cfm.

This tool is extremely useful in a number of ways. For starters, this can be a good first step for consuming a web service. By following the DFB steps, you can see how the service is invoked and in what format the returned data arrives—all without having to read any documentation or WSDL files.

The DFB is also an invaluable testing resource when you are developing web services. Because everything is generated automatically, you can see if you are requiring the correct inputs, have the right methods exposed remotely, and analyze how your information is returned.

There are three basic steps to using the DFB:

  1. Enter the full URL of the WSDL file. Be sure to include "http://". Click the form button to continue.
  2. After the DFB retrieves the name of the service and builds a drop-down list of available methods in that service, select the method you wish to invoke and click the form button.
  3. After the DFB returns any arguments that are required by the method selected in Step 2, enter the appropriate values and click the form button. The DFB will invoke the web service and output the results to the page (using the <cfdump> tag).

An important item to note is the appearance of complex data types in the output from the web service. Because ColdFusion MX uses the underlying Java engine to invoke these web services, what is actually created upon invocation is a Java object, showing both the name of the object and the methods available to that object.

Just remember this: Any method with the "get" prefix (for example, "getCurrentDate()" in the returnObj web service result) can be retrieved in your CFML using CF structure notation. In the example here, to output the data accessible using the returnObj.getCurrentDate() method, you could just use #returnObj.CurrentDate#.

Using the cf_wsdl Custom Tag

The Dynamic Form Builder is really just an implementation of the <cf_wsdl> custom tag. There may be a number of instances where you can simply call on this tag directly. You can use this tag to perform the following actions:

  • Dump the raw WSDL XML text
  • Dump the CF XML object of the WSDL
  • Get the service name
  • Get the methods available in the service
  • Get the arguments that a given method takes
  • Get the type of data that a method returns when invoked correctly

Examples of using the <cf_wsdl> tag to perform the above actions can be found in http://{WSDLerator_root}/test.cfm.

Syntax of cf_wsdl

The <cf_wsdl> tag retrieves information about a web service and its methods using the WSDL document:

 <cf_wsdl 
 action = "action"
 wsdl= "wsdl_url "
 returnVariable = "variablename"
 method = "method_name"> 

Attribute Req/Opt Default Description

action

Required

 

  • dumpRawXML returns the straight WSDL as a string
  • dumpXMLObj returns the WSDL as a CF XML object
  • getServiceName returns the defined name of the web service
  • getRemoteMethods returns an array containing all methods available using the defined web service
  • getMethodArguments returns a query object containing all arguments that a given method takes
  • getReturnType returns a query object containing the type of data returned by a given method

wsdl

Required

 

Full URL of the WSDL that defines the web service

returnVariable

Required

 

Name for the variable that contains the results of this tag

method

Required if action = "getMethodArguments" or "getReturnType"

 

Name of the method that the requested information describes

The query object returned by action="getMethodArguments" contains the following columns:

  • name : name of the argument
  • type : data type of the argument
  • minOccurs : minimum number of values for this argument
  • maxOccurs : maximum number of values for this argument
  • typeNamespace : namespace of the type in the type column (usually either SOAP-ENC or Schema datatypes)
  • typeNamespacePrefix : prefix used in this WSDL document for this namespace

If only a single row is returned containing no type, this indicates that the web service does not require any arguments. The code in the DFB (formBuilder.cfm) shows how this is used.

(For more information on namespaces, refer to the XML section of the ColdFusion documentation.)

The query object returned by action="getReturnType" contains the following columns:

  • name : name of the parameter
  • type : datatype of the parameter
  • minOccurs : minimum number of values for this parameter
  • maxOccurs : maximum number of values for this parameter
  • typeNamespace : namespace of the type in the type column (usually either SOAP-ENC or Schema datatypes); used to find more information about the type
  • typeNamespacePrefix : prefix used in this WSDL document for this namespace
  • subStructName : an object of some sort containing data, if this is not an empty string; used in more complex return types featuring arrays and embedded objects